package com.ych.modules.cms.authorInfc.user.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.ych.modules.base.dbEntity.TUserRaffleTicketEntity;
import com.ych.modules.common.entity.query.QueryUserRaffleTicketEntity;
import com.ych.modules.common.service.UserRaffleTicketService;
import com.ych.utils.mysqlPageUtil.PageUtils;
import com.ych.utils.serviceReturn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2021/1/2
 * Time: 11:43
 * Description:
 */
@RestController("cmsUserRaffleTicketControllerr")
@RequestMapping("/cms/auth/user/raffle/ticket")
@Api(tags = {"CMS——用户抽奖券相关"}, description = "CMS——用户抽奖券相关", position = 2)
public class UserRaffleTicketController {
    @Autowired
    private UserRaffleTicketService userRaffleTicketService;

    @PostMapping("/getRaffleTicket")
    @ApiOperation(value = "抽奖券查询", notes = "抽奖券查询")
    public R<TUserRaffleTicketEntity> getRaffleTicket(@RequestBody String ticketId) {
        try {
            TUserRaffleTicketEntity ticketEntity = userRaffleTicketService.getRaffleTicket(ticketId);
            return new R(0, "成功", ticketEntity);
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }

    @PostMapping("/listRaffleTicket")
    @ApiOperation(value = "查询抽奖券列表", notes = "查询抽奖券列表")
    public R<Page<TUserRaffleTicketEntity>> listRaffleTicket(@RequestBody QueryUserRaffleTicketEntity entity) {
        try {
            Page<TUserRaffleTicketEntity> page = userRaffleTicketService.listRaffleTicket(entity);
            return new R(0, "成功", new PageUtils(page));
        } catch (Exception e) {
            return new R(1, e.getMessage(), null);
        }
    }
}
